package net.wanho.hospital.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.hospital.po.Admin;
import net.wanho.hospital.po.Doctor;
import net.wanho.hospital.service.AdminUserService;
import net.wanho.hospital.service.DoctorUserService;
import net.wanho.hospital.service.OrdersService;
import net.wanho.hospital.service.PatientUserService;
import net.wanho.hospital.vo.AdminVo;
import net.wanho.hospital.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import java.io.Serializable;
import java.util.Map;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2023-12-27
 */
@Api(tags = "01.管理员接口")
@RestController
@RequestMapping("/admin")
@RequiredArgsConstructor
public class AdminUserController {

    private final AdminUserService adminUserService;
    private final PatientUserService patientUserService;
    private final OrdersService ordersService;
    private final DoctorUserService doctorUserService;

    @ApiOperation("分页查询")
    @GetMapping("/findAllPatients")
    public AjaxResult findPatientPage(@ApiParam("当前页") int pageNumber,@ApiParam("页大小") int size, String query){
        Map<String,Object> map = patientUserService.findPatientPage(pageNumber,size, query);
        return AjaxResult.success(map);
    }

    @GetMapping("/findAllOrders")
    public AjaxResult findAllOrders(@ApiParam("当前页") int pageNumber,@ApiParam("页大小") int size, String query){
        Map<String,Object> map = ordersService.findAllOrders(pageNumber,size, query);
        return AjaxResult.success(map);
    }

    @ApiOperation("按主键查询")
    @GetMapping("/{aId}")
    public AjaxResult getById(@ApiParam("学号") @PathVariable Serializable aId){
        return AjaxResult.success(adminUserService.getById(aId));
    }

    @ApiOperation("新增")
    @PostMapping
    public AjaxResult add(@RequestBody Admin stu){
        adminUserService.save(stu);
        return AjaxResult.success();
    }

    @ApiOperation("修改")
    @PutMapping
    public AjaxResult edit(@RequestBody Admin admin){
        adminUserService.updateById(admin);
        return AjaxResult.success();
    }

    @ApiOperation("按主键删除")
    @DeleteMapping("/{aId}")
    public AjaxResult removeById(@ApiParam("学号") @PathVariable Serializable aId){
        adminUserService.removeById(aId);
        return AjaxResult.success();
    }

    @PostMapping("/login")
    public AjaxResult login(int aId, String aPassword){
        AdminVo adminVo = adminUserService.login(aId, aPassword);
        return AjaxResult.success(adminVo);
    }

    @GetMapping("/findDoctor")
    public AjaxResult findDoctor(Integer dId){
        Doctor doctor = doctorUserService.findDoctor(dId);
        return AjaxResult.success(doctor);

    }
}
